@extends('layout.master')

@section('title','订单列表')

@section('css')
    @parent
    <!-- animation CSS -->
    <link href="{{ asset('css/animate.css') }}" rel="stylesheet">
    <!--alerts CSS -->
    <link href="{{ asset('plugins/bower_components/sweetalert/sweetalert.css') }}" rel="stylesheet" type="text/css">
    <!--My admin Custom CSS -->
    <link href="{{ asset('plugins/bower_components/owl.carousel/owl.carousel.min.css') }}" rel="stylesheet"
          type="text/css"/>
    <link href="{{ asset('plugins/bower_components/owl.carousel/owl.theme.default.css') }}" rel="stylesheet"
          type="text/css"/>
    <!-- Popup CSS -->
    <link href="{{ asset('plugins/bower_components/Magnific-Popup-master/dist/magnific-popup.css') }}" rel="stylesheet">
    <style>
        .floating-labels .radioInput label {
            position: static;
        }

    </style>
@endsection
@section('main')
    @if (session('message'))
        <div>
            <input type="hidden" id="hidden" name="hidden" value="hidden">
            <input type="hidden" id="message" name="message" value="{{ session('message') }}">
        </div>
    @endif
    <div class="modal fade" id="express" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel1">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="exampleModalLabel1">填写快递信息</h4>
                </div>
                <div class="modal-body">
                    <form class="floating-labels express" id="express">
                        <input id="express-id" name="id" type="hidden" value="">
                        <fieldset style="border:0;">

                            <div class="form-group m-b-40 m-t-10">
                                <input type="text" class="form-control" id="express-name" name="express_name" required><span
                                        class="highlight"></span> <span class="bar"></span>
                                <label for="input1">快递名称</label>
                            </div>
                            <div class="form-group m-b-40">
                                <input type="text" class="form-control" id="express-order" name="express_order"
                                       required><span
                                        class="highlight"></span> <span class="bar"></span>
                                <label for="input2">快递单号</label>
                            </div>
                            <div class="form-actions">
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="row">
                                            <div class="col-md-offset-3 col-md-9">
                                                <button type="button" class="btn btn-default" data-dismiss="modal">取消
                                                </button>
                                                {!! csrf_field() !!}
                                                <button type="submit" class="btn btn-success" id="express-ok"><i
                                                            class="fa fa-check"></i> 保存
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </fieldset>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <div class="white-box">
        <h3 class="box-title m-b-0">订单列表</h3>
        <hr>
        <div class="table-responsive">
            <table id="example23"
                   class="display nowrap table table-striped table-bordered table-hover order-column my-table "
                   cellspacing="0" width="100%" data-url="{{ url(request()->getUri()) }}">
                <thead>
                <tr>
                    <th>订单ID</th>
                    <th>订单号</th>
                    <th>收货人</th>
                    <th>联系方式</th>
                  	<th>数量</th>
                    <th>订单类型</th>
                    <th>地址</th>
                    <th>送货方式</th>
                    <th>发货</th>
                </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </div>
@endsection
@section('js')
    @parent
    <!-- jQuery for carousel -->
    <script src="{{ asset('plugins/bower_components/owl.carousel/owl.carousel.min.js') }}"></script>
    <script src="{{ asset('plugins/bower_components/owl.carousel/owl.custom.js') }}"></script>

    <!-- jQuery file upload -->
    <script src="{{ asset('plugins/bower_components/dropify/dist/js/dropify.min.js') }}"></script>
    <script>

        var url = $('#example23').data('url');
        var obj = $('#example23');
        obj.DataTable({
            dom: 'Bfrtip',
            buttons: [
                'copy', 'csv', 'excel', 'pdf', 'print'
            ],
            "ordering": false,
            "processing": true,
            "responsive": false,
            "lengthMenu": [
                [10, 20, 50, 100],
                ['10 行', '20 行', '50 行', '100 行']
            ],
            "language": {
                "sProcessing": '<div id="fountainG"><div id="fountainG_1" class="fountainG"></div><div id="fountainG_2" class="fountainG"></div><div id="fountainG_3" class="fountainG"></div><div id="fountainG_4" class="fountainG"></div><div id="fountainG_5" class="fountainG"></div><div id="fountainG_6" class="fountainG"></div><div id="fountainG_7" class="fountainG"></div><div id="fountainG_8" class="fountainG"></div></div>',
                "sLengthMenu": "显示 _MENU_ 项结果",
                "sZeroRecords": "没有匹配结果",
                "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
                "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
                "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                "sInfoPostFix": "",
                "sSearch": "搜索:",
                "sUrl": "",
                "sEmptyTable": "暂无记录",
                "sLoadingRecords": "载入中...",
                "sInfoThousands": ",",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "上一页",
                    "sNext": "下一页",
                    "sLast": "末页"
                }
            },
            serverSide: true,
            ajax: {
                url: url,
                type: 'POST',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            },
            "deferRender": true
        });
        $('.column_filter').on('change', function () {
            obj.DataTable().column($(this).data('column')).search($(this).val(), false, true).draw();
        });
        //跳转页
        $("#example23").append("  到第 <input type='text' id='changePage' class='input-text' style='width:50px;height:27px'> 页 ");
        var oTable = $("#example23").dataTable();
        $('#changePage').keyup(function (e) {
            if ($(this).val() && $(this).val() > 0) {
                var redirectpage = $(this).val() - 1;
            } else {
                var redirectpage = 0;
            }
            $('#all').removeAttr('checked');
            $('.label-all').text('全选');
            oTable.fnPageChange(redirectpage);
        });



        $(document).ready(function () {
            var hidden = $('#hidden').val();
            if (hidden === 'hidden') {
                toastsuccess($('#message').val());
            }
        });

        //快递发货
        function edit(sid) {
            $('#express-id').val(sid);
        }
        $('#express').submit(function (e) {
            e.preventDefault();
            var id = $('#express-id').val();
            var express_name = $('#express-name').val();
            var express_order = $('#express-order').val();
            console.log(id,express_name,express_order);
            swal({
                    title: "",
                    text: "确定发货么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/promotion/promotionSend',
                        data: {'id':id, 'delivery':2, 'express_name':express_name, 'express_order':express_order},
                        type: 'POST',
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        });

        //人工配送
        obj.on('click', '.btn-manual', function () {
            var id = $(this).data('id');
            swal({
                    title: "",
                    text: "确定发货么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/promotion/promotionSend',
                        data: {'id':id, 'delivery':1},
                        type: 'POST',
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        });

    </script>
    <!-- icheck -->
    <script src="{{ asset('plugins/bower_components/icheck/icheck.min.js') }}"></script>
    <script src="{{ asset('plugins/bower_components/icheck/icheck.init.js') }}"></script>
    <script src="{{ asset('js/jasny-bootstrap.js') }}"></script>
    <!-- Magnific popup JavaScript -->
    <script src="{{ asset('plugins/bower_components/Magnific-Popup-master/dist/jquery.magnific-popup.min.js') }}"></script>
    <script src="{{ asset('plugins/bower_components/Magnific-Popup-master/dist/jquery.magnific-popup-init.js') }}"></script>
@endsection